package leetcode.code876.MiddleoftheLinkedList;

import leetcode.helper.tree.ListNode;

/**
 * @author Max
 * @date 2021年8月16日
 * @description
 */
public abstract class MiddleoftheLinkedList implements IMiddleoftheLinkedList {

	/**
	 * 提示：给定链表的结点数介于 1 和 100 之间。
	 */
	@Override
	abstract public ListNode middleNode(ListNode head);

	@Override
	public ListNode debug(ListNode head) {
		ListNode res = this.middleNode(head);
		ListNode p = res;
		while (p != null) {
			System.out.print(p.val + ",");
			p = p.next;
		}
		return null;
	}

	@Override
	public ListNode debug1() {
		Integer[] array = new Integer[] { 1, 2, 3, 4, 5 };
		this.myPrint("1, 2, 3, 4, 5", "3,4,5");
		this.debug(this.makeList(array));
		return null;
	}

	@Override
	public ListNode debug2() {
		Integer[] array = new Integer[] { 1, 2, 3, 4, 5, 6 };
		this.myPrint("1, 2, 3, 4, 5, 6", "4,5,6");
		this.debug(this.makeList(array));
		return null;
	}

	private ListNode makeList(Integer[] array) {
		ListNode head = new ListNode(array[0]);
		int len = array.length;
		ListNode p = head;
		for (int i = 1; i < len; i++) {
			p.next = new ListNode(array[i]);
			p = p.next;
		}
		return head;
	}

	private void myPrint(String data, String expect) {
		System.out.println("数据：" + data);
		System.out.println("期望：" + expect);
		System.out.print("结果：");
	}

}
